<li><a href="#patch-and-POSIX">10.12 <samp><span class="command">patch</span></samp> and the <span class="sc">posix</span> Standard</a>
<li><a href="#patch-and-Tradition">10.13 <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> and Traditional <samp><span class="command">patch</span></samp></a>
</li></ul>
<li><a name="toc_Making-Patches" href="#Making-Patches">11 Tips for Making and Using Patches</a>
<ul>
<li><a href="#Tips-for-Patch-Producers">11.1 Tips for Patch Producers</a>
<li><a href="#Tips-for-Patch-Consumers">11.2 Tips for Patch Consumers</a>
<li><a href="#Avoiding-Common-Mistakes">11.3 Avoiding Common Mistakes</a>
When comparing two files, <samp><span class="command">diff</span></samp> finds sequences of lines common to
both files, interspersed with groups of differing lines called
<dfn>hunks</dfn>. Comparing two identical files yields one sequence of
common lines and no hunks, because no lines differ. Comparing two
entirely different files yields no common lines and one large hunk that
contains all lines of both files. In general, there are many ways to
match up lines between two given files. <samp><span class="command">diff</span></samp> tries to minimize
the total hunk size by finding large sequences of common lines
interspersed with small hunks of differing lines.
<p>For example, suppose the file <samp><span class="file">F</span></samp> contains the three lines
`<samp><span class="samp">a</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">c</span></samp>', and the file <samp><span class="file">G</span></samp> contains the same
three lines in reverse order `<samp><span class="samp">c</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">a</span></samp>'. If
<samp><span class="command">diff</span></samp> finds the line `<samp><span class="samp">c</span></samp>' as common, then the command
`<samp><span class="samp">diff F G</span></samp>' produces this output:
<pre class="example"> 1,2d0
< a
< b
3a2,3
> b
> a
</pre>
<p class="noindent">But if <samp><span class="command">diff</span></samp> notices the common line `<samp><span class="samp">b</span></samp>' instead, it produces
this output:
<pre class="example"> 1c1
< a
---
> c
3c3
< c
---
> a
</pre>
<p class="noindent">It is also possible to find `<samp><span class="samp">a</span></samp>' as the common line. <samp><span class="command">diff</span></samp>
does not always find an optimal matching between the files; it takes
shortcuts to run faster. But its output is usually close to the
shortest possible. You can adjust this tradeoff with the
<samp><span class="option">--minimal</span></samp> option (see <a href="#diff-Performance">diff Performance</a>).
<span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can treat lower case letters as equivalent to their
upper case counterparts, so that, for example, it considers `<samp><span class="samp">Funky
Stuff</span></samp>', `<samp><span class="samp">funky STUFF</span></samp>', and `<samp><span class="samp">fUNKy stuFf</span></samp>' to all be the same.
To request this, use the <samp><span class="option">-i</span></samp> or <samp><span class="option">--ignore-case</span></samp> option.
<h4 class="subsection">2.2.1 Detailed Description of Normal Format</h4>
<p>The normal output format consists of one or more hunks of differences;
each hunk shows one area where the files differ. Normal format hunks
look like this:
<pre class="example"> <var>change-command</var>
< <var>from-file-line</var>
< <var>from-file-line</var>...
---
> <var>to-file-line</var>
> <var>to-file-line</var>...
</pre>
<p>There are three types of change commands. Each consists of a line
number or comma-separated range of lines in the first file, a single
character indicating the kind of change to make, and a line number or
comma-separated range of lines in the second file. All line numbers are
the original line numbers in each file. The types of change commands
are:
<dl>
<dt>`<samp><var>l</var><span class="samp">a</span><var>r</var></samp>'<dd>Add the lines in range <var>r</var> of the second file after line <var>l</var> of
the first file. For example, `<samp><span class="samp">8a12,15</span></samp>' means append lines 12–15
of file 2 after line 8 of file 1; or, if changing file 2 into file 1,
delete lines 12–15 of file 2.
<br><dt>`<samp><var>f</var><span class="samp">c</span><var>t</var></samp>'<dd>Replace the lines in range <var>f</var> of the first file with lines in range
<var>t</var> of the second file. This is like a combined add and delete, but
more compact. For example, `<samp><span class="samp">5,7c8,10</span></samp>' means change lines 5–7 of
file 1 to read as lines 8–10 of file 2; or, if changing file 2 into
file 1, change lines 8–10 of file 2 to read as lines 5–7 of file 1.
<br><dt>`<samp><var>r</var><span class="samp">d</span><var>l</var></samp>'<dd>Delete the lines in range <var>r</var> from the first file; line <var>l</var> is where
they would have appeared in the second file had they not been deleted.
For example, `<samp><span class="samp">5,7d3</span></samp>' means delete lines 5–7 of file 1; or, if
changing file 2 into file 1, append lines 5–7 of file 1 after line 3 of
<p>The context output format shows several lines of context around the
lines that differ. It is the standard format for distributing updates
to source code.
<p>To select this output format, use the <samp><span class="option">-C </span><var>lines</var></samp>,
<samp><span class="option">--context[=</span><var>lines</var><span class="option">]</span></samp>, or <samp><span class="option">-c</span></samp> option. The
argument <var>lines</var> that some of these options take is the number of
lines of context to show. If you do not specify <var>lines</var>, it
defaults to three. For proper operation, <samp><span class="command">patch</span></samp> typically needs
at least two lines of context.
<ul class="menu">
<li><a accesskey="1" href="#Detailed-Context">Detailed Context</a>: A detailed description of the context output format.
<li><a accesskey="2" href="#Example-Context">Example Context</a>: Sample output in context format.
<li><a accesskey="3" href="#Less-Context">Less Context</a>: Another sample with less context.
<p class="noindent"><a name="index-LC_005fTIME-21"></a><a name="index-time-stamp-format_002c-context-diffs-22"></a>The time stamp normally looks like `<samp><span class="samp">2002-02-21 23:30:39.942229878
-0800</span></samp>' to indicate the date, time with fractional seconds, and time
zone in <a href="ftp://ftp.isi.edu/in-notes/rfc2822.txt">Internet RFC 2822 format</a>. However, a traditional time stamp like `<samp><span class="samp">Thu Feb 21
23:30:39 2002</span></samp>' is used if the <samp><span class="env">LC_TIME</span></samp> locale category is either
`<samp><span class="samp">C</span></samp>' or `<samp><span class="samp">POSIX</span></samp>'.
<p>You can change the header's content with the
<samp><span class="option">--label=</span><var>label</var></samp> option; see <a href="#Alternate-Names">Alternate Names</a>.
<p>Next come one or more hunks of differences; each hunk shows one area
where the files differ. Context format hunks look like this:
<pre class="example"> ***************
*** <var>from-file-line-range</var> ****
<var>from-file-line</var>
<var>from-file-line</var>...
--- <var>to-file-line-range</var> ----
<var>to-file-line</var>
<var>to-file-line</var>...
</pre>
<p>The lines of context around the lines that differ start with two space
characters. The lines that differ between the two files start with one
of the following indicator characters, followed by a space character:
<dl>
<dt>`<samp><span class="samp">!</span></samp>'<dd>A line that is part of a group of one or more lines that changed between
the two files. There is a corresponding group of lines marked with
`<samp><span class="samp">!</span></samp>' in the part of this hunk for the other file.
<br><dt>`<samp><span class="samp">+</span></samp>'<dd>An “inserted” line in the second file that corresponds to nothing in
the first file.
<br><dt>`<samp><span class="samp">-</span></samp>'<dd>A “deleted” line in the first file that corresponds to nothing in the
second file.
</dl>
<p>If all of the changes in a hunk are insertions, the lines of
<var>from-file</var> are omitted. If all of the changes are deletions, the
<h5 class="subsubsection">2.3.1.3 An Example of Context Format with Less Context</h5>
<p>Here is the output of `<samp><span class="samp">diff -C 1 lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files). Notice that at
Several output modes produce command scripts for editing <var>from-file</var>
to produce <var>to-file</var>.
<ul class="menu">
<li><a accesskey="1" href="#ed-Scripts">ed Scripts</a>: Using <samp><span class="command">diff</span></samp> to produce commands for <samp><span class="command">ed</span></samp>.
<li><a accesskey="2" href="#Forward-ed">Forward ed</a>: Making forward <samp><span class="command">ed</span></samp> scripts.
<li><a accesskey="3" href="#RCS">RCS</a>: A special <samp><span class="command">diff</span></samp> output format used by <span class="sc">rcs</span>.
<samp><span class="command">diff</span></samp> can produce commands that direct the <samp><span class="command">ed</span></samp> text editor
to change the first file into the second file. Long ago, this was the
only output mode that was suitable for editing one file into another
automatically; today, with <samp><span class="command">patch</span></samp>, it is almost obsolete. Use the
<samp><span class="option">-e</span></samp> or <samp><span class="option">--ed</span></samp> option to select this output format.
<p>Like the normal format (see <a href="#Normal">Normal</a>), this output format does not
show any context; unlike the normal format, it does not include the
information necessary to apply the diff in reverse (to produce the first
file if all you have is the second file and the diff).
<p>If the file <samp><span class="file">d</span></samp> contains the output of `<samp><span class="samp">diff -e old new</span></samp>', then
the command `<samp><span class="samp">(cat d && echo w) | ed - old</span></samp>' edits <samp><span class="file">old</span></samp> to make
it a copy of <samp><span class="file">new</span></samp>. More generally, if <samp><span class="file">d1</span></samp>, <samp><span class="file">d2</span></samp>,
<small class="dots">...</small>, <samp><span class="file">dN</span></samp> contain the outputs of `<samp><span class="samp">diff -e old new1</span></samp>',
<h5 class="subsubsection">2.5.1.2 Example <samp><span class="command">ed</span></samp> Script</h5>
<p>Here is the output of `<samp><span class="samp">diff -e lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
The <span class="sc">rcs</span> output format is designed specifically for use by the Revision
Control System, which is a set of free programs used for organizing
different versions and systems of files. Use the <samp><span class="option">-n</span></samp> or
<samp><span class="option">--rcs</span></samp> option to select this output format. It is like the
forward <samp><span class="command">ed</span></samp> format (see <a href="#Forward-ed">Forward ed</a>), but it can represent
arbitrary changes to the contents of a file because it avoids the
forward <samp><span class="command">ed</span></samp> format's problems with lines consisting of a single
period and with incomplete lines. Instead of ending text sections with
a line consisting of a single period, each command specifies the number
of lines it affects; a combination of the `<samp><span class="samp">a</span></samp>' and `<samp><span class="samp">d</span></samp>'
commands are used instead of `<samp><span class="samp">c</span></samp>'. Also, if the second file ends
in a changed incomplete line, then the output also ends in an
incomplete line.
<p>Here is the output of `<samp><span class="samp">diff -n lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
Line group formats let you specify formats suitable for many
applications that allow if-then-else input, including programming
languages and text formatting languages. A line group format specifies
the output format for a contiguous group of similar lines.
<p>For example, the following command compares the TeX files <samp><span class="file">old</span></samp>
and <samp><span class="file">new</span></samp>, and outputs a merged file in which old regions are
surrounded by `<samp><span class="samp">\begin{em}</span></samp>'-`<samp><span class="samp">\end{em}</span></samp>' lines, and new
regions are surrounded by `<samp><span class="samp">\begin{bf}</span></samp>'-`<samp><span class="samp">\end{bf}</span></samp>' lines.
<pre class="example"> diff \
--old-group-format='\begin{em}
%<\end{em}
' \
--new-group-format='\begin{bf}
%>\end{bf}
' \
old new
</pre>
<p>The following command is equivalent to the above example, but it is a
little more verbose, because it spells out the default line group formats.
<pre class="example"> diff \
--old-group-format='\begin{em}
%<\end{em}
' \
--new-group-format='\begin{bf}
%>\end{bf}
' \
--unchanged-group-format='%=' \
--changed-group-format='\begin{em}
%<\end{em}
\begin{bf}
%>\end{bf}
' \
old new
</pre>
<p>Here is a more advanced example, which outputs a diff listing with
headers containing line numbers in a “plain English” style.
<pre class="example"> diff \
--unchanged-group-format='' \
--old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
%<' \
--new-group-format='-------- %dN line%(N=1?:s) added after %de:
%>' \
--changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
%<-------- to:
%>' \
old new
</pre>
<p>To specify a line group format, use <samp><span class="command">diff</span></samp> with one of the options
listed below. You can specify up to four line group formats, one for
each kind of line group. You should quote <var>format</var>, because it
typically contains shell metacharacters.
<dl>
<dt><samp><span class="option">--old-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing only lines from the first file.
The default old group format is the same as the changed group format if
it is specified; otherwise it is a format that outputs the line group as-is.
<br><dt><samp><span class="option">--new-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing only lines from the second
file. The default new group format is same as the changed group
format if it is specified; otherwise it is a format that outputs the
line group as-is.
<br><dt><samp><span class="option">--changed-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing lines from both files. The
default changed group format is the concatenation of the old and new
group formats.
<br><dt><samp><span class="option">--unchanged-group-format=</span><var>format</var></samp><dd>These line groups contain lines common to both files. The default
unchanged group format is a format that outputs the line group as-is.
</dl>
<p>In a line group format, ordinary characters represent themselves;
conversion specifications start with `<samp><span class="samp">%</span></samp>' and have one of the
following forms.
<dl>
<dt>`<samp><span class="samp">%<</span></samp>'<dd>stands for the lines from the first file, including the trailing newline.
Each line is formatted according to the old line format (see <a href="#Line-Formats">Line Formats</a>).
<br><dt>`<samp><span class="samp">%></span></samp>'<dd>stands for the lines from the second file, including the trailing newline.
Each line is formatted according to the new line format.
<br><dt>`<samp><span class="samp">%=</span></samp>'<dd>stands for the lines common to both files, including the trailing newline.
Each line is formatted according to the unchanged line format.
<br><dt>`<samp><span class="samp">%%</span></samp>'<dd>stands for `<samp><span class="samp">%</span></samp>'.
<br><dt>`<samp><span class="samp">%c'</span><var>C</var><span class="samp">'</span></samp>'<dd>where <var>C</var> is a single character, stands for <var>C</var>.
<var>C</var> may not be a backslash or an apostrophe.
For example, `<samp><span class="samp">%c':'</span></samp>' stands for a colon, even inside
the then-part of an if-then-else format, which a colon would
normally terminate.
<br><dt>`<samp><span class="samp">%c'\</span><var>O</var><span class="samp">'</span></samp>'<dd>where <var>O</var> is a string of 1, 2, or 3 octal digits,
stands for the character with octal code <var>O</var>.
For example, `<samp><span class="samp">%c'\0'</span></samp>' stands for a null character.
<br><dt>`<samp><var>F</var><var>n</var></samp>'<dd>where <var>F</var> is a <code>printf</code> conversion specification and <var>n</var> is one
of the following letters, stands for <var>n</var>'s value formatted with <var>F</var>.
<dl>
<dt>`<samp><span class="samp">e</span></samp>'<dd>The line number of the line just before the group in the old file.
<br><dt>`<samp><span class="samp">f</span></samp>'<dd>The line number of the first line in the group in the old file;
equals <var>e</var> + 1.
<br><dt>`<samp><span class="samp">l</span></samp>'<dd>The line number of the last line in the group in the old file.
<br><dt>`<samp><span class="samp">m</span></samp>'<dd>The line number of the line just after the group in the old file;
equals <var>l</var> + 1.
<br><dt>`<samp><span class="samp">n</span></samp>'<dd>The number of lines in the group in the old file; equals <var>l</var> - <var>f</var> + 1.
<br><dt>`<samp><span class="samp">E, F, L, M, N</span></samp>'<dd>Likewise, for lines in the new file.
</dl>
<p><a name="index-LC_005fNUMERIC-48"></a>The <code>printf</code> conversion specification can be `<samp><span class="samp">%d</span></samp>',
`<samp><span class="samp">%o</span></samp>', `<samp><span class="samp">%x</span></samp>', or `<samp><span class="samp">%X</span></samp>', specifying decimal, octal,
lower case hexadecimal, or upper case hexadecimal output
respectively. After the `<samp><span class="samp">%</span></samp>' the following options can appear in
sequence: a series of zero or more flags; an integer
specifying the minimum field width; and a period followed by an
optional integer specifying the minimum number of digits.
The flags are `<samp><span class="samp">-</span></samp>' for left-justification, `<samp><span class="samp">'</span></samp>' for separating
the digit into groups as specified by the <samp><span class="env">LC_NUMERIC</span></samp> locale category,
and `<samp><span class="samp">0</span></samp>' for padding with zeros instead of spaces.
For example, `<samp><span class="samp">%5dN</span></samp>' prints the number of new lines in the group
in a field of width 5 characters, using the <code>printf</code> format <code>"%5d"</code>.
Line formats control how each line taken from an input file is
output as part of a line group in if-then-else format.
<p>For example, the following command outputs text with a one-character
change indicator to the left of the text. The first character of output
is `<samp><span class="samp">-</span></samp>' for deleted lines, `<samp><span class="samp">|</span></samp>' for added lines, and a space for
unchanged lines. The formats contain newline characters where newlines
are desired on output.
<pre class="example"> diff \
--old-line-format='-%l
' \
--new-line-format='|%l
' \
--unchanged-line-format=' %l
' \
old new
</pre>
<p>To specify a line format, use one of the following options. You should
quote <var>format</var>, since it often contains shell metacharacters.
<dl>
<dt><samp><span class="option">--old-line-format=</span><var>format</var></samp><dd>formats lines just from the first file.
<br><dt><samp><span class="option">--new-line-format=</span><var>format</var></samp><dd>formats lines just from the second file.
<br><dt><samp><span class="option">--unchanged-line-format=</span><var>format</var></samp><dd>formats lines common to both files.
<br><dt><samp><span class="option">--line-format=</span><var>format</var></samp><dd>formats all lines; in effect, it sets all three above options simultaneously.
</dl>
<p>In a line format, ordinary characters represent themselves;
conversion specifications start with `<samp><span class="samp">%</span></samp>' and have one of the
following forms.
<dl>
<dt>`<samp><span class="samp">%l</span></samp>'<dd>stands for the contents of the line, not counting its trailing
newline (if any). This format ignores whether the line is incomplete;
See <a href="#Incomplete-Lines">Incomplete Lines</a>.
<br><dt>`<samp><span class="samp">%L</span></samp>'<dd>stands for the contents of the line, including its trailing newline
(if any). If a line is incomplete, this format preserves its
incompleteness.
<br><dt>`<samp><span class="samp">%%</span></samp>'<dd>stands for `<samp><span class="samp">%</span></samp>'.
<br><dt>`<samp><span class="samp">%c'</span><var>C</var><span class="samp">'</span></samp>'<dd>where <var>C</var> is a single character, stands for <var>C</var>.
<var>C</var> may not be a backslash or an apostrophe.
For example, `<samp><span class="samp">%c':'</span></samp>' stands for a colon.
<br><dt>`<samp><span class="samp">%c'\</span><var>O</var><span class="samp">'</span></samp>'<dd>where <var>O</var> is a string of 1, 2, or 3 octal digits,
stands for the character with octal code <var>O</var>.
For example, `<samp><span class="samp">%c'\0'</span></samp>' stands for a null character.
<br><dt>`<samp><var>F</var><span class="samp">n</span></samp>'<dd>where <var>F</var> is a <code>printf</code> conversion specification,
stands for the line number formatted with <var>F</var>.
For example, `<samp><span class="samp">%.5dn</span></samp>' prints the line number using the
<code>printf</code> format <code>"%.5d"</code>. See <a href="#Line-Group-Formats">Line Group Formats</a>, for
more about printf conversion specifications.
</dl>
<p>The default line format is `<samp><span class="samp">%l</span></samp>' followed by a newline character.
<p>If the input contains tab characters and it is important that they line
up on output, you should ensure that `<samp><span class="samp">%l</span></samp>' or `<samp><span class="samp">%L</span></samp>' in a line
format is just after a tab stop (e.g. by preceding `<samp><span class="samp">%l</span></samp>' or
`<samp><span class="samp">%L</span></samp>' with a tab character), or you should use the <samp><span class="option">-t</span></samp> or
<h4 class="subsection">2.6.4 An Example of If-then-else Format</h4>
<p>Here is the output of `<samp><span class="samp">diff -DTWO lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
<pre class="example"> #ifndef TWO
The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
When an input file ends in a non-newline character, its last line is
called an <dfn>incomplete line</dfn> because its last character is not a
newline. All other lines are called <dfn>full lines</dfn> and end in a
newline character. Incomplete lines do not match full lines unless
differences in white space are ignored (see <a href="#White-Space">White Space</a>).
<p>An incomplete line is normally distinguished on output from a full line
by a following line that starts with `<samp><span class="samp">\</span></samp>'. However, the <span class="sc">rcs</span> format
(see <a href="#RCS">RCS</a>) outputs the incomplete line as-is, without any trailing
newline or following line. The side by side format normally represents
incomplete lines as-is, but in some cases uses a `<samp><span class="samp">\</span></samp>' or `<samp><span class="samp">/</span></samp>'
gutter marker; See <a href="#Side-by-Side">Side by Side</a>. The if-then-else line format
preserves a line's incompleteness with `<samp><span class="samp">%L</span></samp>', and discards the
newline with `<samp><span class="samp">%l</span></samp>'; See <a href="#Line-Formats">Line Formats</a>. Finally, with the
<samp><span class="command">ed</span></samp> and forward <samp><span class="command">ed</span></samp> output formats (see <a href="#Output-Formats">Output Formats</a>)
<samp><span class="command">diff</span></samp> cannot represent an incomplete line, so it pretends there
was a newline and reports an error.
<p>For example, suppose <samp><span class="file">F</span></samp> and <samp><span class="file">G</span></samp> are one-byte files that
contain just `<samp><span class="samp">f</span></samp>' and `<samp><span class="samp">g</span></samp>', respectively. Then `<samp><span class="samp">diff F G</span></samp>'
outputs
<pre class="example"> 1c1
< f
\ No newline at end of file
---
> g
\ No newline at end of file
</pre>
<p class="noindent">(The exact message may differ in non-English locales.)
`<samp><span class="samp">diff -n F G</span></samp>' outputs the following without a trailing newline:
<pre class="example"> d1 1
a1 1
g
</pre>
<p class="noindent">`<samp><span class="samp">diff -e F G</span></samp>' reports two errors and outputs the following:
The lines of text in some of the <samp><span class="command">diff</span></samp> output formats are preceded
by one or two characters that indicate whether the text is inserted,
deleted, or changed. The addition of those characters can cause tabs to
move to the next tab stop, throwing off the alignment of columns in the
line. <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> provides two ways to make tab-aligned columns
line up correctly.
<p>The first way is to have <samp><span class="command">diff</span></samp> convert all tabs into the correct
number of spaces before outputting them; select this method with the
<samp><span class="option">-t</span></samp> or <samp><span class="option">--expand-tabs</span></samp> option. <samp><span class="command">diff</span></samp> assumes that
tab stops are set every 8 print columns. To use this form of output with
<samp><span class="command">patch</span></samp>, you must give <samp><span class="command">patch</span></samp> the <samp><span class="option">-l</span></samp> or
<samp><span class="option">--ignore-white-space</span></samp> option (see <a href="#Changed-White-Space">Changed White Space</a>, for more
information).
<p>The other method for making tabs line up correctly is to add a tab
character instead of a space after the indicator character at the
beginning of the line. This ensures that all following tab characters
are in the same position relative to tab stops that they were in the
original files, so that the output is aligned correctly. Its
disadvantage is that it can make long lines too long to fit on one line
of the screen or the paper. It also does not work with the unified
output format, which does not have a space character after the change
type indicator character. Select this method with the <samp><span class="option">-T</span></samp> or
Here is a third sample file that will be used in examples to illustrate
the output of <samp><span class="command">diff3</span></samp> and how various options can change it. The
first two files are the same that we used for <samp><span class="command">diff</span></samp> (see <a href="#Sample-diff-Input">Sample diff Input</a>). This is the third sample file, called <samp><span class="file">tao</span></samp>:
<pre class="example"> The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
Up: <a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>
</div>
<h3 class="section">7.2 Detailed Description of <samp><span class="command">diff3</span></samp> Normal Format</h3>
<p>Each hunk begins with a line marked `<samp><span class="samp">====</span></samp>'. Three-way hunks have
plain `<samp><span class="samp">====</span></samp>' lines, and two-way hunks have `<samp><span class="samp">1</span></samp>', `<samp><span class="samp">2</span></samp>', or
`<samp><span class="samp">3</span></samp>' appended to specify which of the three input files differ in
that hunk. The hunks contain copies of two or three sets of input
lines each preceded by one or two commands identifying where the lines
came from.
<p>Normally, two spaces precede each copy of an input line to distinguish
it from the commands. But with the <samp><span class="option">-T</span></samp> or <samp><span class="option">--initial-tab</span></samp>
option, <samp><span class="command">diff3</span></samp> uses a tab instead of two spaces; this lines up
tabs correctly. See <a href="#Tabs">Tabs</a>, for more information.
<p>Commands take the following forms:
<dl>
<dt>`<samp><var>file</var><span class="samp">:</span><var>l</var><span class="samp">a</span></samp>'<dd>This hunk appears after line <var>l</var> of file <var>file</var>, and
contains no lines in that file. To edit this file to yield the other
files, one must append hunk lines taken from the other files. For
example, `<samp><span class="samp">1:11a</span></samp>' means that the hunk follows line 11 in the first
file and contains no lines from that file.
<br><dt>`<samp><var>file</var><span class="samp">:</span><var>r</var><span class="samp">c</span></samp>'<dd>This hunk contains the lines in the range <var>r</var> of file <var>file</var>.
The range <var>r</var> is a comma-separated pair of line numbers, or just one
number if the range is a singleton. To edit this file to yield the
other files, one must change the specified lines to be the lines taken
from the other files. For example, `<samp><span class="samp">2:11,13c</span></samp>' means that the hunk
contains lines 11 through 13 from the second file.
</dl>
<p>If the last line in a set of input lines is incomplete
(see <a href="#Incomplete-Lines">Incomplete Lines</a>), it is distinguished on output from a full
line by a following line that starts with `<samp><span class="samp">\</span></samp>'.
<samp><span class="command">diff3</span></samp> can mark conflicts in the merged output by
bracketing them with special marker lines. A conflict
that comes from two files <var>A</var> and <var>B</var> is marked as follows:
<pre class="example"> <<<<<<< <var>A</var>
<span class="roman">lines from </span><var>A</var>
=======
<span class="roman">lines from </span><var>B</var>
>>>>>>> <var>B</var>
</pre>
<p>A conflict that comes from three files <var>A</var>, <var>B</var> and <var>C</var> is
marked as follows:
<pre class="example"> <<<<<<< <var>A</var>
<span class="roman">lines from </span><var>A</var>
||||||| <var>B</var>
<span class="roman">lines from </span><var>B</var>
=======
<span class="roman">lines from </span><var>C</var>
>>>>>>> <var>C</var>
</pre>
<p>The <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option acts like the <samp><span class="option">-e</span></samp>
option, except that it brackets conflicts, and it outputs all changes
from <var>older</var> to <var>yours</var>, not just the unmerged changes. Thus,
given the sample input files (see <a href="#Sample-diff3-Input">Sample diff3 Input</a>), `<samp><span class="samp">diff3
-A lao tzu tao</span></samp>' puts brackets around the conflict where only <samp><span class="file">tzu</span></samp>
differs:
<pre class="example"> <<<<<<< tzu
=======
The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
>>>>>>> tao
</pre>
<p>And it outputs the three-way conflict as follows:
<pre class="example"> <<<<<<< lao
||||||| tzu
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!
=======
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
>>>>>>> tao
</pre>
<p>The <samp><span class="option">-E</span></samp> or <samp><span class="option">--show-overlap</span></samp> option outputs less information
than the <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option, because it outputs only
unmerged changes, and it never outputs the contents of the second
file. Thus the <samp><span class="option">-E</span></samp> option acts like the <samp><span class="option">-e</span></samp> option,
except that it brackets the first and third files from three-way
overlapping changes. Similarly, <samp><span class="option">-X</span></samp> acts like <samp><span class="option">-x</span></samp>, except
it brackets all its (necessarily overlapping) changes. For example,
for the three-way overlapping change above, the <samp><span class="option">-E</span></samp> and <samp><span class="option">-X</span></samp>
options output the following:
<pre class="example"> <<<<<<< lao
=======
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
>>>>>>> tao
</pre>
<p>If you are comparing files that have meaningless or uninformative names,
you can use the <samp><span class="option">-L </span><var>label</var></samp> or <samp><span class="option">--label=</span><var>label</var></samp>
option to show alternate names in the `<samp><span class="samp"><<<<<<<</span></samp>', `<samp><span class="samp">|||||||</span></samp>'
and `<samp><span class="samp">>>>>>>></span></samp>' brackets. This option can be given up to three
times, once for each input file. Thus `<samp><span class="samp">diff3 -A -L X -L Y -L Z A
B C</span></samp>' acts like `<samp><span class="samp">diff3 -A A B C</span></samp>', except that the output looks like
it came from files named `<samp><span class="samp">X</span></samp>', `<samp><span class="samp">Y</span></samp>' and `<samp><span class="samp">Z</span></samp>' rather than
from files named `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>' and `<samp><span class="samp">C</span></samp>'.
With the <samp><span class="option">-m</span></samp> or <samp><span class="option">--merge</span></samp> option, <samp><span class="command">diff3</span></samp> outputs the
merged file directly. This is more efficient than using <samp><span class="command">ed</span></samp> to
generate it, and works even with non-text files that <samp><span class="command">ed</span></samp> would
reject. If you specify <samp><span class="option">-m</span></samp> without an <samp><span class="command">ed</span></samp> script option,
<samp><span class="option">-A</span></samp> (<samp><span class="option">--show-all</span></samp>) is assumed.
<p>For example, the command `<samp><span class="samp">diff3 -m lao tzu tao</span></samp>'
(see <a href="#Sample-diff3-Input">Sample diff3 Input</a> for a copy of the input files) would output
the following:
<pre class="example"> <<<<<<< tzu
=======
The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
>>>>>>> tao
The Nameless is the origin of Heaven and Earth;
The Named is the mother of all things.
Therefore let there always be non-being,
so we may see their subtlety,
And let there always be being,
so we may see their result.
The two are the same,
But after they are produced,
they have different names.
<<<<<<< lao
||||||| tzu
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!
=======
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
>>>>>>> tao
</pre>
<div class="node">
<p><hr>
<a name="Merging-Incomplete-Lines"></a>
Next: <a rel="next" accesskey="n" href="#Saving-the-Changed-File">Saving the Changed File</a>,
Traditional Unix <samp><span class="command">diff3</span></samp> generates an <samp><span class="command">ed</span></samp> script without the
trailing `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>' commands that save the changes.
System V <samp><span class="command">diff3</span></samp> generates these extra commands. <span class="sc">gnu</span>
<samp><span class="command">diff3</span></samp> normally behaves like traditional Unix
<samp><span class="command">diff3</span></samp>, but with the <samp><span class="option">-i</span></samp> option it behaves like
System V <samp><span class="command">diff3</span></samp> and appends the `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>'
commands.
<p>The <samp><span class="option">-i</span></samp> option requires one of the <samp><span class="command">ed</span></samp> script options
<samp><span class="option">-AeExX3</span></samp>, and is incompatible with the merged output option
<samp><span class="option">-m</span></samp>.
<div class="node">
<p><hr>
<a name="Interactive-Merging"></a>
Next: <a rel="next" accesskey="n" href="#Merging-with-patch">Merging with patch</a>,
<p>For historical reasons, <samp><span class="command">sdiff</span></samp> has alternate names for some
options. The <samp><span class="option">-l</span></samp> option is equivalent to the
<samp><span class="option">--left-column</span></samp> option, and similarly <samp><span class="option">-s</span></samp> is equivalent
to <samp><span class="option">--suppress-common-lines</span></samp>. The meaning of the <samp><span class="command">sdiff</span></samp>
<samp><span class="option">-w</span></samp> and <samp><span class="option">-W</span></samp> options is interchanged from that of
<samp><span class="command">diff</span></samp>: with <samp><span class="command">sdiff</span></samp>, <samp><span class="option">-w </span><var>columns</var></samp> is
equivalent to <samp><span class="option">--width=</span><var>columns</var></samp>, and <samp><span class="option">-W</span></samp> is
equivalent to <samp><span class="option">--ignore-all-space</span></samp>. <samp><span class="command">sdiff</span></samp> without the
<samp><span class="option">-o</span></samp> option is equivalent to <samp><span class="command">diff</span></samp> with the <samp><span class="option">-y</span></samp>
or <samp><span class="option">--side-by-side</span></samp> option (see <a href="#Side-by-Side">Side by Side</a>).
Groups of common lines, with a blank gutter, are copied from the first
file to the output. After each group of differing lines, <samp><span class="command">sdiff</span></samp>
prompts with `<samp><span class="samp">%</span></samp>' and pauses, waiting for one of the following
commands. Follow each command with <RET>.
<dl>
<dt>`<samp><span class="samp">e</span></samp>'<dd>Discard both versions.
Invoke a text editor on an empty temporary file,
then copy the resulting file to the output.
<br><dt>`<samp><span class="samp">eb</span></samp>'<dd>Concatenate the two versions, edit the result in a temporary file,
then copy the edited result to the output.
<br><dt>`<samp><span class="samp">ed</span></samp>'<dd>Like `<samp><span class="samp">eb</span></samp>', except precede each version with a header that
shows what file and lines the version came from.
<br><dt>`<samp><span class="samp">el</span></samp>'<dd>Edit a copy of the left version, then copy the result to the output.
<br><dt>`<samp><span class="samp">er</span></samp>'<dd>Edit a copy of the right version, then copy the result to the output.
<br><dt>`<samp><span class="samp">l</span></samp>'<dd>Copy the left version to the output.
<li><a href="#patch-Messages">patch Messages</a>: Messages and questions <samp><span class="command">patch</span></samp> can produce.
<li><a href="#patch-and-POSIX">patch and POSIX</a>: Conformance to the <span class="sc">posix</span> standard.
<li><a href="#patch-and-Tradition">patch and Tradition</a>: <span class="sc">gnu</span> versus traditional <samp><span class="command">patch</span></samp>.
Sometimes people run <samp><span class="command">diff</span></samp> with the new file first instead of
second. This creates a diff that is “reversed”. To apply such
patches, give <samp><span class="command">patch</span></samp> the <samp><span class="option">-R</span></samp> or <samp><span class="option">--reverse</span></samp> option.
<samp><span class="command">patch</span></samp> then attempts to swap each hunk around before applying it.
Rejects come out in the swapped format.
<p>Often <samp><span class="command">patch</span></samp> can guess that the patch is reversed. If the first
hunk of a patch fails, <samp><span class="command">patch</span></samp> reverses the hunk to see if it can
apply it that way. If it can, <samp><span class="command">patch</span></samp> asks you if you want to have
the <samp><span class="option">-R</span></samp> option set; if it can't, <samp><span class="command">patch</span></samp> continues to apply
the patch normally. This method cannot detect a reversed patch if it is
a normal diff and the first command is an append (which should have been
a delete) since appends always succeed, because a null context matches
anywhere. But most patches add or change lines rather than delete them,
so most reversed normal diffs begin with a delete, which fails, and
For context diffs, and to a lesser extent normal diffs, <samp><span class="command">patch</span></samp> can
detect when the line numbers mentioned in the patch are incorrect, and
it attempts to find the correct place to apply each hunk of the patch.
As a first guess, it takes the line number mentioned in the hunk, plus
or minus any offset used in applying the previous hunk. If that is not
the correct place, <samp><span class="command">patch</span></samp> scans both forward and backward for a
set of lines matching the context given in the hunk.
<p>First <samp><span class="command">patch</span></samp> looks for a place where all lines of the context
match. If it cannot find such a place, and it is reading a context or
unified diff, and the maximum fuzz factor is set to 1 or more, then
<samp><span class="command">patch</span></samp> makes another scan, ignoring the first and last line of
context. If that fails, and the maximum fuzz factor is set to 2 or
more, it makes another scan, ignoring the first two and last two lines
of context are ignored. It continues similarly if the maximum fuzz
factor is larger.
<p>The <samp><span class="option">-F </span><var>lines</var></samp> or <samp><span class="option">--fuzz=</span><var>lines</var></samp> option sets the
maximum fuzz factor to <var>lines</var>. This option only applies to context
and unified diffs; it ignores up to <var>lines</var> lines while looking for
the place to install a hunk. Note that a larger fuzz factor increases
the odds of making a faulty patch. The default fuzz factor is 2; there
is no point to setting it to more than the number of lines of context
in the diff, ordinarily 3.
<p>If <samp><span class="command">patch</span></samp> cannot find a place to install a hunk of the patch, it
writes the hunk out to a reject file (see <a href="#Reject-Names">Reject Names</a>, for information
on how reject files are named). It writes out rejected hunks in context
format no matter what form the input patch is in. If the input is a
normal or <samp><span class="command">ed</span></samp> diff, many of the contexts are simply null. The
line numbers on the hunks in the reject file may be different from those
in the patch file: they show the approximate location where <samp><span class="command">patch</span></samp>
thinks the failed hunks belong in the new file rather than in the old
one.
<p>If the <samp><span class="option">--verbose</span></samp> option is given, then
as it completes each hunk <samp><span class="command">patch</span></samp> tells you whether the hunk
succeeded or failed, and if it failed, on which line (in the new file)
<samp><span class="command">patch</span></samp> thinks the hunk should go. If this is different from the
line number specified in the diff, it tells you the offset. A single
large offset <em>may</em> indicate that <samp><span class="command">patch</span></samp> installed a hunk in
the wrong place. <samp><span class="command">patch</span></samp> also tells you if it used a fuzz factor
to make the match, in which case you should also be slightly suspicious.
<p><samp><span class="command">patch</span></samp> cannot tell if the line numbers are off in an <samp><span class="command">ed</span></samp>
script, and can only detect wrong line numbers in a normal diff when it
finds a change or delete command. It may have the same problem with a
context diff using a fuzz factor equal to or greater than the number of
lines of context shown in the diff (typically 3). In these cases, you
should probably look at a context diff between your original and patched
input files to see if the changes make sense. Compiling without errors
is a pretty good indication that the patch worked, but not a guarantee.
<p>A patch against an empty file applies to a nonexistent file, and vice
versa. See <a href="#Creating-and-Removing">Creating and Removing</a>.
<p><samp><span class="command">patch</span></samp> usually produces the correct results, even when it must
make many guesses. However, the results are guaranteed only when
the patch is applied to an exact copy of the file that the patch was
When <samp><span class="command">patch</span></samp> updates a file, it normally sets the file's
last-modified time stamp to the current time of day. If you are using
<samp><span class="command">patch</span></samp> to track a software distribution, this can cause
<samp><span class="command">make</span></samp> to incorrectly conclude that a patched file is out of
date. For example, if <samp><span class="file">syntax.c</span></samp> depends on <samp><span class="file">syntax.y</span></samp>, and
<samp><span class="command">patch</span></samp> updates <samp><span class="file">syntax.c</span></samp> and then <samp><span class="file">syntax.y</span></samp>, then
<samp><span class="file">syntax.c</span></samp> will normally appear to be out of date with respect to
<samp><span class="file">syntax.y</span></samp> even though its contents are actually up to date.
<p>The <samp><span class="option">-Z</span></samp> or <samp><span class="option">--set-utc</span></samp> option causes <samp><span class="command">patch</span></samp> to
set a patched file's modification and access times to the time stamps
given in context diff headers. If the context diff headers do not
specify a time zone, they are assumed to use Coordinated Universal
Time (<span class="sc">utc</span>, often known as <span class="sc">gmt</span>).
<p>The <samp><span class="option">-T</span></samp> or <samp><span class="option">--set-time</span></samp> option acts like <samp><span class="option">-Z</span></samp> or
<samp><span class="option">--set-utc</span></samp>, except that it assumes that the context diff
headers' time stamps use local time instead of <span class="sc">utc</span>. This option
is not recommended, because patches using local time cannot easily be
used by people in other time zones, and because local time stamps are
ambiguous when local clocks move backwards during daylight-saving time
adjustments. If the context diff headers specify a time zone, this
option is equivalent to <samp><span class="option">-Z</span></samp> or <samp><span class="option">--set-utc</span></samp>.
<p><samp><span class="command">patch</span></samp> normally refrains from setting a file's time stamps if
the file's original last-modified time stamp does not match the time
given in the diff header, of if the file's contents do not exactly
match the patch. However, if the <samp><span class="option">-f</span></samp> or <samp><span class="option">--force</span></samp>
option is given, the file's time stamps are set regardless.
<p>Due to the limitations of the current <samp><span class="command">diff</span></samp> format,
<samp><span class="command">patch</span></samp> cannot update the times of files whose contents have
not changed. Also, if you set file time stamps to values other than
the current time of day, you should also remove (e.g., with `<samp><span class="samp">make
clean</span></samp>') all files that depend on the patched files, so that later
invocations of <samp><span class="command">make</span></samp> do not get confused by the patched
The <samp><span class="option">-d </span><var>directory</var></samp> or <samp><span class="option">--directory=</span><var>directory</var></samp>
option to <samp><span class="command">patch</span></samp> makes directory <var>directory</var> the current
directory for interpreting both file names in the patch file, and file
names given as arguments to other options (such as <samp><span class="option">-B</span></samp> and
<samp><span class="option">-o</span></samp>). For example, while in a mail reading program, you can patch
a file in the <samp><span class="file">/usr/src/emacs</span></samp> directory directly from a message
containing the patch like this:
<pre class="example"> | patch -d /usr/src/emacs
</pre>
<p>Sometimes the file names given in a patch contain leading directories,
but you keep your files in a directory different from the one given in
the patch. In those cases, you can use the
<samp><span class="option">-p</span><var>number</var></samp> or <samp><span class="option">--strip=</span><var>number</var></samp>
option to set the file name strip count to <var>number</var>. The strip
count tells <samp><span class="command">patch</span></samp> how many slashes, along with the directory
names between them, to strip from the front of file names. A sequence
of one or more adjacent slashes is counted as a single slash. By
default, <samp><span class="command">patch</span></samp> strips off all leading directories, leaving
just the base file names.
<p>For example, suppose the file name in the patch file is
<samp><span class="file">/gnu/src/emacs/etc/NEWS</span></samp>. Using <samp><span class="option">-p0</span></samp> gives the
entire file name unmodified, <samp><span class="option">-p1</span></samp> gives
<samp><span class="file">gnu/src/emacs/etc/NEWS</span></samp> (no leading slash), <samp><span class="option">-p4</span></samp> gives
<samp><span class="file">etc/NEWS</span></samp>, and not specifying <samp><span class="option">-p</span></samp> at all gives <samp><span class="file">NEWS</span></samp>.
<p><samp><span class="command">patch</span></samp> looks for each file (after any slashes have been stripped)
in the current directory, or if you used the <samp><span class="option">-d </span><var>directory</var></samp>
Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
</div>
<h3 class="section">10.9 Backup File Names</h3>
<p><a name="index-backup-file-names-104"></a>
Normally, <samp><span class="command">patch</span></samp> renames an original input file into a backup
file by appending to its name the extension `<samp><span class="samp">.orig</span></samp>', or `<samp><span class="samp">~</span></samp>'
if using `<samp><span class="samp">.orig</span></samp>' would make the backup file name too
long.<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a> The <samp><span class="option">-z </span><var>backup-suffix</var></samp> or
<samp><span class="option">--suffix=</span><var>backup-suffix</var></samp> option causes <samp><span class="command">patch</span></samp> to
use <var>backup-suffix</var> as the backup extension instead.
<p><a name="index-SIMPLE_005fBACKUP_005fSUFFIX-105"></a>Alternately, you can specify the extension for backup files with the
<samp><span class="env">SIMPLE_BACKUP_SUFFIX</span></samp> environment variable, which the options
override.
<p><samp><span class="command">patch</span></samp> can also create numbered backup files the way <span class="sc">gnu</span> Emacs
does. With this method, instead of having a single backup of each file,
<samp><span class="command">patch</span></samp> makes a new backup file name each time it patches a file.
For example, the backups of a file named <samp><span class="file">sink</span></samp> would be called,
successively, <samp><span class="file">sink.~1~</span></samp>, <samp><span class="file">sink.~2~</span></samp>, <samp><span class="file">sink.~3~</span></samp>, etc.
<p><a name="index-PATCH_005fVERSION_005fCONTROL-106"></a><a name="index-VERSION_005fCONTROL-107"></a>The <samp><span class="option">-V </span><var>backup-style</var></samp> or
<samp><span class="option">--version-control=</span><var>backup-style</var></samp> option takes as an
argument a method for creating backup file names. You can alternately
control the type of backups that <samp><span class="command">patch</span></samp> makes with the
<samp><span class="env">PATCH_VERSION_CONTROL</span></samp> environment variable, which the
<samp><span class="option">-V</span></samp> option overrides. If <samp><span class="env">PATCH_VERSION_CONTROL</span></samp> is not
set, the <samp><span class="env">VERSION_CONTROL</span></samp> environment variable is used instead.
Please note that these options and variables control backup file
names; they do not affect the choice of revision control system
(see <a href="#Revision-Control">Revision Control</a>).
<p>The values of these environment variables and the argument to the
<samp><span class="option">-V</span></samp> option are like the <span class="sc">gnu</span> Emacs <code>version-control</code>
variable (see <a href="emacs.html#Backup-Names">Backup Names</a>,
for more information on backup versions in Emacs). They also
recognize synonyms that are more descriptive. The valid values are
listed below; unique abbreviations are acceptable.
<dl>
<dt><samp><span class="option">t</span></samp><dt><samp><span class="option">numbered</span></samp><dd>Always make numbered backups.
<br><dt><samp><span class="option">nil</span></samp><dt><samp><span class="option">existing</span></samp><dd>Make numbered backups of files that already have them, simple backups of
the others. This is the default.
<br><dt><samp><span class="option">never</span></samp><dt><samp><span class="option">simple</span></samp><dd>Always make simple backups.
</dl>
<p>You can also tell <samp><span class="command">patch</span></samp> to prepend a prefix, such as a
directory name, to produce backup file names. The <samp><span class="option">-B
</span><var>prefix</var></samp> or <samp><span class="option">--prefix=</span><var>prefix</var></samp> option makes backup
files by prepending <var>prefix</var> to them. The <samp><span class="option">-Y
</span><var>prefix</var></samp> or <samp><span class="option">--basename-prefix=</span><var>prefix</var></samp> prepends
<var>prefix</var> to the last file name component of backup file names
instead; for example, <samp><span class="option">-Y ~</span></samp> causes the backup name for
<samp><span class="file">dir/file.c</span></samp> to be <samp><span class="file">dir/~file.c</span></samp>. If you use either of
these prefix options, the suffix-based options are ignored.
<p>If you specify the output file with the <samp><span class="option">-o</span></samp> option, that file is
the one that is backed up, not the input file.
<p>Options that affect the names of backup files do not affect whether
backups are made. For example, if you specify the
<samp><span class="option">--no-backup-if-mismatch</span></samp> option, none of the options described
in this section have any affect, because no backups are made.
<samp><span class="command">patch</span></samp> can produce a variety of messages, especially if it
has trouble decoding its input. In a few situations where it's not
sure how to proceed, <samp><span class="command">patch</span></samp> normally prompts you for more
information from the keyboard. There are options to produce more or
fewer messages, to have it not ask for keyboard input, and to
affect the way that file names are quoted in messages.
<ul class="menu">
<li><a accesskey="1" href="#More-or-Fewer-Messages">More or Fewer Messages</a>: Controlling the verbosity of <samp><span class="command">patch</span></samp>.
<li><a accesskey="2" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>: Inhibiting keyboard input.
<li><a accesskey="3" href="#patch-Quoting-Style">patch Quoting Style</a>: Quoting file names in diagnostics.
</ul>
<p><samp><span class="command">patch</span></samp> exits with status 0 if all hunks are applied successfully,
1 if some hunks cannot be applied, and 2 if there is more serious trouble.
When applying a set of patches in a loop, you should check the
exit status, so you don't apply a later patch to a partially patched
file.
<div class="node">
<p><hr>
<a name="More-or-Fewer-Messages"></a>
Next: <a rel="next" accesskey="n" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>,
You can cause <samp><span class="command">patch</span></samp> to produce more messages by using the
<samp><span class="option">--verbose</span></samp> option. For example, when you give this option,
the message `<samp><span class="samp">Hmm...</span></samp>' indicates that <samp><span class="command">patch</span></samp> is reading text in
the patch file, attempting to determine whether there is a patch in that
text, and if so, what kind of patch it is.
<p>You can inhibit all terminal output from <samp><span class="command">patch</span></samp>, unless an error
occurs, by using the <samp><span class="option">-s</span></samp>, <samp><span class="option">--quiet</span></samp>, or <samp><span class="option">--silent</span></samp>
There are two ways you can prevent <samp><span class="command">patch</span></samp> from asking you any
questions. The <samp><span class="option">-f</span></samp> or <samp><span class="option">--force</span></samp> option assumes that you know
what you are doing. It causes <samp><span class="command">patch</span></samp> to do the following:
<ul>
<li>Skip patches that do not contain file names in their headers.
<li>Patch files even though they have the wrong version for the
`<samp><span class="samp">Prereq:</span></samp>' line in the patch;
<li>Assume that patches are not reversed even if they look like they are.
</ul>
<p class="noindent">The <samp><span class="option">-t</span></samp> or <samp><span class="option">--batch</span></samp> option is similar to <samp><span class="option">-f</span></samp>, in that
it suppresses questions, but it makes somewhat different assumptions:
<ul>
<li>Skip patches that do not contain file names in their headers
(the same as <samp><span class="option">-f</span></samp>).
<li>Skip patches for which the file has the wrong version for the
`<samp><span class="samp">Prereq:</span></samp>' line in the patch;
<li>Assume that patches are reversed if they look like they are.
</ul>
<div class="node">
<p><hr>
<a name="patch-Quoting-Style"></a>
Previous: <a rel="previous" accesskey="p" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>,
<br><dt>`<samp><span class="samp">shell</span></samp>'<dd>Quote names for the shell if they contain shell metacharacters or would
cause ambiguous output.
<br><dt>`<samp><span class="samp">shell-always</span></samp>'<dd>Quote names for the shell, even if they would normally not require quoting.
<br><dt>`<samp><span class="samp">c</span></samp>'<dd>Quote names as for a C language string.
<br><dt>`<samp><span class="samp">escape</span></samp>'<dd>Quote as with `<samp><span class="samp">c</span></samp>' except omit the surrounding double-quote
characters.
<!-- The following are not yet implemented in patch 2.5.4. -->
<!-- @item clocale -->
<!-- Quote as with @samp{c} except use quotation marks appropriate for the -->
<!-- locale. -->
<!-- @item locale -->
<!-- @c Use @t instead of @samp to avoid duplicate quoting in some output styles. -->
<!-- Like @samp{clocale}, but quote @t{`like this'} instead of @t{"like -->
<!-- this"} in the default C locale. This looks nicer on many displays. -->
</dl>
<p><a name="index-QUOTING_005fSTYLE-116"></a>You can specify the default value of the <samp><span class="option">--quoting-style</span></samp>
option with the environment variable <samp><span class="env">QUOTING_STYLE</span></samp>. If that
environment variable is not set, the default value is `<samp><span class="samp">shell</span></samp>',
but this default may change in a future version of <samp><span class="command">patch</span></samp>.
<div class="node">
<p><hr>
<a name="patch-and-POSIX"></a>
Next: <a rel="next" accesskey="n" href="#patch-and-Tradition">patch and Tradition</a>,
more strictly to the <span class="sc">posix</span> standard, as follows:
<ul>
<li>Take the first existing file from the list (old, new, index)
when intuiting file names from diff headers. See <a href="#Multiple-Patches">Multiple Patches</a>.
<li>Do not remove files that are removed by a diff.
See <a href="#Creating-and-Removing">Creating and Removing</a>.
<li>Do not ask whether to get files from <span class="sc">rcs</span>, ClearCase, or
<span class="sc">sccs</span>. See <a href="#Revision-Control">Revision Control</a>.
<li>Require that all options precede the files in the command line.
<li>Do not backup files, even when there is a mismatch. See <a href="#Backups">Backups</a>.
</ul>
<div class="node">
<p><hr>
<a name="patch-and-Tradition"></a>
Previous: <a rel="previous" accesskey="p" href="#patch-and-POSIX">patch and POSIX</a>,
Up: <a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>
</div>
<h3 class="section">10.13 <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> and Traditional <samp><span class="command">patch</span></samp></h3>
Previous: <a rel="previous" accesskey="p" href="#Merging-with-patch">Merging with patch</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">11 Tips for Making and Using Patches</h2>
<p>Use some common sense when making and using patches. For example,
when sending bug fixes to a program's maintainer, send several small
patches, one per independent subject, instead of one large,
harder-to-digest patch that covers all the subjects.
<p>Here are some other things you should keep in mind if you are going to
distribute patches for updating a software package.
<ul class="menu">
<li><a accesskey="1" href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>: Advice for making patches.
<li><a accesskey="2" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>: Advice for using patches.
<li><a accesskey="3" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>: Avoiding common mistakes when using <samp><span class="command">patch</span></samp>.
<li><a accesskey="4" href="#Generating-Smaller-Patches">Generating Smaller Patches</a>: How to generate smaller patches.
</ul>
<div class="node">
<p><hr>
<a name="Tips-for-Patch-Producers"></a>
Next: <a rel="next" accesskey="n" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>,
The simplest way to generate a patch is to use `<samp><span class="samp">diff -Naur</span></samp>'
(see <a href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>), but you might be able to reduce
the size of the patch by renaming or removing some files before making
the patch. If the older version of the package contains any files
that the newer version does not, or if any files have been renamed
between the two versions, make a list of <samp><span class="command">rm</span></samp> and <samp><span class="command">mv</span></samp>
commands for the user to execute in the old version directory before
applying the patch. Then run those commands yourself in the scratch
directory.
<p>If there are any files that you don't need to include in the patch
because they can easily be rebuilt from other files (for example,
<samp><span class="file">TAGS</span></samp> and output from <samp><span class="command">yacc</span></samp> and <samp><span class="command">makeinfo</span></samp>),
exclude them from the patch by giving <samp><span class="command">diff</span></samp> the <samp><span class="option">-x
</span><var>pattern</var></samp> option (see <a href="#Comparing-Directories">Comparing Directories</a>). If you want
your patch to modify a derived file because your recipients lack tools
to build it, make sure that the patch for the derived file follows any
patches for files that it depends on, so that the recipients' time
stamps will not confuse <samp><span class="command">make</span></samp>.
<p>Now you can create the patch using `<samp><span class="samp">diff -Naur</span></samp>'. Make sure to
specify the scratch directory first and the newer directory second.
<p>Add to the top of the patch a note telling the user any <samp><span class="command">rm</span></samp> and
<samp><span class="command">mv</span></samp> commands to run before applying the patch. Then you can
remove the scratch directory.
<p>You can also shrink the patch size by using fewer lines of context,
but bear in mind that <samp><span class="command">patch</span></samp> typically needs at least two
lines for proper operation when patches do not exactly match the input
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp> accepts.
Most options have two equivalent names, one of which is a single letter
preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name preceded by
`<samp><span class="samp">--</span></samp>'. Multiple single letter options (unless they take an
argument) can be combined into a single command line word: <samp><span class="option">-bl</span></samp> is
equivalent to <samp><span class="option">-b -l</span></samp>.
<dl>
<dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--print-bytes</span></samp><dd>Print the differing bytes. Display control bytes as a
`<samp><span class="samp">^</span></samp>' followed by a letter of the alphabet and precede bytes
that have the high bit set with `<samp><span class="samp">M-</span></samp>' (which stands for “meta”).
<br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
<br><dt><samp><span class="option">-i </span><var>skip</var></samp><dt><samp><span class="option">--ignore-initial=</span><var>skip</var></samp><dd>Ignore any differences in the first <var>skip</var> bytes of the input
files. Treat files with fewer than <var>skip</var> bytes as if they are
empty. If <var>skip</var> is of the form
<samp><var>from-skip</var><span class="option">:</span><var>to-skip</var></samp>, skip the first <var>from-skip</var>
bytes of the first input file and the first <var>to-skip</var> bytes of the
second.
<br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--verbose</span></samp><dd>Print the (decimal) byte numbers and (octal) values of all differing bytes.
<br><dt><samp><span class="option">-n </span><var>count</var></samp><dt><samp><span class="option">--bytes=</span><var>count</var></samp><dd>Compare at most <var>count</var> input bytes.
<br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd>Do not print anything; only return an exit status indicating whether
the files differ.
<br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
</dl>
<p>In the above table, operands that are byte counts are normally
decimal, but may be preceded by `<samp><span class="samp">0</span></samp>' for octal and `<samp><span class="samp">0x</span></samp>' for
hexadecimal.
<p>A byte count can be followed by a suffix to specify a multiple of that
count; in this case an omitted integer is understood to be 1. A bare
size letter, or one followed by `<samp><span class="samp">iB</span></samp>', specifies a multiple using
powers of 1024. A size letter followed by `<samp><span class="samp">B</span></samp>' specifies powers
of 1000 instead. For example, <samp><span class="option">-n 4M</span></samp> and <samp><span class="option">-n 4MiB</span></samp> are
equivalent to <samp><span class="option">-n 4194304</span></samp>, whereas <samp><span class="option">-n 4MB</span></samp> is
equivalent to <samp><span class="option">-n 4000000</span></samp>. This notation is upward compatible
with the <a href="http://www.bipm.fr/enus/3_SI/si-prefixes.html">SI prefixes</a> for decimal multiples and with the
<a href="http://physics.nist.gov/cuu/Units/binary.html">IEC 60027-2 prefixes for binary multiples</a>.
<p>The following suffixes are defined. Large sizes like <code>1Y</code> may be
rejected by your computer due to limitations of its arithmetic.
<br><dt>`<samp><span class="samp">k</span></samp>'<dt>`<samp><span class="samp">K</span></samp>'<dt>`<samp><span class="samp">KiB</span></samp>'<dd><a name="index-kibibyte_002c-definition-of-130"></a>kibibyte: 2^10 = 1024. `<samp><span class="samp">K</span></samp>' is special: the SI prefix is
`<samp><span class="samp">k</span></samp>' and the IEC 60027-2 prefix is `<samp><span class="samp">Ki</span></samp>', but tradition and
<span class="sc">posix</span> use `<samp><span class="samp">k</span></samp>' to mean `<samp><span class="samp">KiB</span></samp>'.
<p>In the simplest case, two file names <var>from-file</var> and
<var>to-file</var> are given, and <samp><span class="command">diff</span></samp> compares the contents of
<var>from-file</var> and <var>to-file</var>. A file name of <samp><span class="file">-</span></samp> stands for
text read from the standard input. As a special case, `<samp><span class="samp">diff - -</span></samp>'
compares a copy of standard input to itself.
<p>If one file is a directory and the other is not, <samp><span class="command">diff</span></samp> compares
the file in the directory whose name is that of the non-directory.
The non-directory file must not be <samp><span class="file">-</span></samp>.
<p>If two file names are given and both are directories,
<samp><span class="command">diff</span></samp> compares corresponding files in both directories, in
alphabetical order; this comparison is not recursive unless the
<samp><span class="option">-r</span></samp> or <samp><span class="option">--recursive</span></samp> option is given. <samp><span class="command">diff</span></samp> never
compares the actual contents of a directory as if it were a file. The
file that is fully specified may not be standard input, because standard
input is nameless and the notion of “file with the same name” does not
apply.
<p>If the <samp><span class="option">--from-file=</span><var>file</var></samp> option is given, the number of
file names is arbitrary, and <var>file</var> is compared to each named file.
Similarly, if the <samp><span class="option">--to-file=</span><var>file</var></samp> option is given, each
named file is compared to <var>file</var>.
<p><samp><span class="command">diff</span></samp> options begin with `<samp><span class="samp">-</span></samp>', so normally file names
may not begin with `<samp><span class="samp">-</span></samp>'. However, <samp><span class="option">--</span></samp> as an
argument by itself treats the remaining arguments as file names even if
they begin with `<samp><span class="samp">-</span></samp>'.
<p>An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.
<ul class="menu">
<li><a accesskey="1" href="#diff-Options">diff Options</a>: Summary of options to <samp><span class="command">diff</span></samp>.
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> accepts.
Most options have two equivalent names, one of which is a single letter
preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name preceded by
`<samp><span class="samp">--</span></samp>'. Multiple single letter options (unless they take an
argument) can be combined into a single command line word: <samp><span class="option">-ac</span></samp> is
equivalent to <samp><span class="option">-a -c</span></samp>. Long named options can be abbreviated to
any unique prefix of their name. Brackets ([ and ]) indicate that an
option takes an optional argument.
<dl>
<dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
do not seem to be text. See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--ignore-space-change</span></samp><dd>Ignore changes in amount of white space. See <a href="#White-Space">White Space</a>.
<br><dt><samp><span class="option">-B</span></samp><dt><samp><span class="option">--ignore-blank-lines</span></samp><dd>Ignore changes that just insert or delete blank lines. See <a href="#Blank-Lines">Blank Lines</a>.
<br><dt><samp><span class="option">--binary</span></samp><dd>Read and write data in binary mode. See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">-c</span></samp><dd>Use the context output format, showing three lines of context.
See <a href="#Context-Format">Context Format</a>.
<br><dt><samp><span class="option">-C </span><var>lines</var></samp><dt><samp><span class="option">--context[=</span><var>lines</var><span class="option">]</span></samp><dd>Use the context output format, showing <var>lines</var> (an integer) lines of
context, or three if <var>lines</var> is not given. See <a href="#Context-Format">Context Format</a>.
For proper operation, <samp><span class="command">patch</span></samp> typically needs at least two lines of
context.
<p>On older systems, <samp><span class="command">diff</span></samp> supports an obsolete option
<samp><span class="option">-</span><var>lines</var></samp> that has effect when combined with <samp><span class="option">-c</span></samp>
or <samp><span class="option">-p</span></samp>. <span class="sc">posix</span> 1003.1-2001 (see <a href="#Standards-conformance">Standards conformance</a>) does not allow this; use <samp><span class="option">-C </span><var>lines</var></samp>
instead.
<br><dt><samp><span class="option">--changed-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line group containing differing lines from
both files in if-then-else format. See <a href="#Line-Group-Formats">Line Group Formats</a>.
<br><dt><samp><span class="option">-d</span></samp><dt><samp><span class="option">--minimal</span></samp><dd>Change the algorithm perhaps find a smaller set of changes. This makes
<samp><span class="command">diff</span></samp> slower (sometimes much slower). See <a href="#diff-Performance">diff Performance</a>.
<br><dt><samp><span class="option">-D </span><var>name</var></samp><dt><samp><span class="option">--ifdef=</span><var>name</var></samp><dd>Make merged `<samp><span class="samp">#ifdef</span></samp>' format output, conditional on the preprocessor
macro <var>name</var>. See <a href="#If_002dthen_002delse">If-then-else</a>.
<br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Make output that is a valid <samp><span class="command">ed</span></samp> script. See <a href="#ed-Scripts">ed Scripts</a>.
<br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--ignore-tab-expansion</span></samp><dd>Ignore changes due to tab expansion.
See <a href="#White-Space">White Space</a>.
<br><dt><samp><span class="option">-f</span></samp><dt><samp><span class="option">--forward-ed</span></samp><dd>Make output that looks vaguely like an <samp><span class="command">ed</span></samp> script but has changes
in the order they appear in the file. See <a href="#Forward-ed">Forward ed</a>.
<br><dt><samp><span class="option">-F </span><var>regexp</var></samp><dt><samp><span class="option">--show-function-line=</span><var>regexp</var></samp><dd>In context and unified format, for each hunk of differences, show some
of the last preceding line that matches <var>regexp</var>. See <a href="#Specified-Headings">Specified Headings</a>.
<br><dt><samp><span class="option">--from-file=</span><var>file</var></samp><dd>Compare <var>file</var> to each operand; <var>file</var> may be a directory.
<br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
<br><dt><samp><span class="option">--horizon-lines=</span><var>lines</var></samp><dd>Do not discard the last <var>lines</var> lines of the common prefix
and the first <var>lines</var> lines of the common suffix.
See <a href="#diff-Performance">diff Performance</a>.
<br><dt><samp><span class="option">-i</span></samp><dt><samp><span class="option">--ignore-case</span></samp><dd>Ignore changes in case; consider upper- and lower-case letters
equivalent. See <a href="#Case-Folding">Case Folding</a>.
<br><dt><samp><span class="option">-I </span><var>regexp</var></samp><dt><samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp><dd>Ignore changes that just insert or delete lines that match <var>regexp</var>.
See <a href="#Specified-Folding">Specified Folding</a>.
<br><dt><samp><span class="option">--ignore-file-name-case</span></samp><dd>Ignore case when comparing file names during recursive comparison.
See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--paginate</span></samp><dd>Pass the output through <samp><span class="command">pr</span></samp> to paginate it. See <a href="#Pagination">Pagination</a>.
<br><dt><samp><span class="option">--label=</span><var>label</var></samp><dd>Use <var>label</var> instead of the file name in the context format
(see <a href="#Context-Format">Context Format</a>) and unified format (see <a href="#Unified-Format">Unified Format</a>)
headers. See <a href="#RCS">RCS</a>.
<br><dt><samp><span class="option">--left-column</span></samp><dd>Print only the left column of two common lines in side by side format.
See <a href="#Side-by-Side-Format">Side by Side Format</a>.
<br><dt><samp><span class="option">--line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output all input lines in if-then-else format.
See <a href="#Line-Formats">Line Formats</a>.
<br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--rcs</span></samp><dd>Output <span class="sc">rcs</span>-format diffs; like <samp><span class="option">-f</span></samp> except that each command
specifies the number of lines affected. See <a href="#RCS">RCS</a>.
<br><dt><samp><span class="option">-N</span></samp><dt><samp><span class="option">--new-file</span></samp><dd>In directory comparison, if a file is found in only one directory,
treat it as present but empty in the other directory. See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">--new-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of lines taken from just the second
file in if-then-else format. See <a href="#Line-Group-Formats">Line Group Formats</a>.
<br><dt><samp><span class="option">--new-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line taken from just the second file in
if-then-else format. See <a href="#Line-Formats">Line Formats</a>.
<br><dt><samp><span class="option">--old-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of lines taken from just the first
file in if-then-else format. See <a href="#Line-Group-Formats">Line Group Formats</a>.
<br><dt><samp><span class="option">--old-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line taken from just the first file in
if-then-else format. See <a href="#Line-Formats">Line Formats</a>.
<br><dt><samp><span class="option">-p</span></samp><dt><samp><span class="option">--show-c-function</span></samp><dd>Show which C function each change is in. See <a href="#C-Function-Headings">C Function Headings</a>.
<br><dt><samp><span class="option">-q</span></samp><dt><samp><span class="option">--brief</span></samp><dd>Report only whether the files differ, not the details of the
differences. See <a href="#Brief">Brief</a>.
<br><dt><samp><span class="option">-r</span></samp><dt><samp><span class="option">--recursive</span></samp><dd>When comparing directories, recursively compare any subdirectories
found. See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--report-identical-files</span></samp><dd>Report when two files are the same. See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">-S </span><var>file</var></samp><dt><samp><span class="option">--starting-file=</span><var>file</var></samp><dd>When comparing directories, start with the file <var>file</var>. This is
used for resuming an aborted comparison. See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">--speed-large-files</span></samp><dd>Use heuristics to speed handling of large files that have numerous
scattered small changes. See <a href="#diff-Performance">diff Performance</a>.
<br><dt><samp><span class="option">--strip-trailing-cr</span></samp><dd>Strip any trailing carriage return at the end of an input line.
See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">--suppress-common-lines</span></samp><dd>Do not print common lines in side by side format.
See <a href="#Side-by-Side-Format">Side by Side Format</a>.
<br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--expand-tabs</span></samp><dd>Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files. See <a href="#Tabs">Tabs</a>.
<br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--initial-tab</span></samp><dd>Output a tab rather than a space before the text of a line in normal or
context format. This causes the alignment of tabs in the line to look
normal. See <a href="#Tabs">Tabs</a>.
<br><dt><samp><span class="option">--to-file=</span><var>file</var></samp><dd>Compare each operand to <var>file</var>; <var>file</var> may be a directory.
<br><dt><samp><span class="option">-u</span></samp><dd>Use the unified output format, showing three lines of context.
See <a href="#Unified-Format">Unified Format</a>.
<br><dt><samp><span class="option">--unchanged-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of common lines taken from both files
in if-then-else format. See <a href="#Line-Group-Formats">Line Group Formats</a>.
<br><dt><samp><span class="option">--unchanged-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line common to both files in if-then-else
format. See <a href="#Line-Formats">Line Formats</a>.
<br><dt><samp><span class="option">--unidirectional-new-file</span></samp><dd>When comparing directories, if a file appears only in the second
directory of the two, treat it as present but empty in the other.
See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">-U </span><var>lines</var></samp><dt><samp><span class="option">--unified[=</span><var>lines</var><span class="option">]</span></samp><dd>Use the unified output format, showing <var>lines</var> (an integer) lines of
context, or three if <var>lines</var> is not given. See <a href="#Unified-Format">Unified Format</a>.
For proper operation, <samp><span class="command">patch</span></samp> typically needs at least two lines of
context.
<p>On older systems, <samp><span class="command">diff</span></samp> supports an obsolete option
<samp><span class="option">-</span><var>lines</var></samp> that has effect when combined with <samp><span class="option">-u</span></samp>.
<span class="sc">posix</span> 1003.1-2001 (see <a href="#Standards-conformance">Standards conformance</a>) does not allow
this; use <samp><span class="option">-U </span><var>lines</var></samp> instead.
<br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
<br><dt><samp><span class="option">-w</span></samp><dt><samp><span class="option">--ignore-all-space</span></samp><dd>Ignore white space when comparing lines. See <a href="#White-Space">White Space</a>.
<br><dt><samp><span class="option">-W </span><var>columns</var></samp><dt><samp><span class="option">--width=</span><var>columns</var></samp><dd>Output at most <var>columns</var> (default 130) print columns per line in
side by side format. See <a href="#Side-by-Side-Format">Side by Side Format</a>.
match any pattern contained in <var>file</var>. See <a href="#Comparing-Directories">Comparing Directories</a>.
<br><dt><samp><span class="option">-y</span></samp><dt><samp><span class="option">--side-by-side</span></samp><dd>Use the side by side output format. See <a href="#Side-by-Side-Format">Side by Side Format</a>.
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">diff3</span></samp>
accepts. Multiple single letter options (unless they take an argument)
can be combined into a single command line argument.
<dl>
<dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
do not appear to be text. See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">-A</span></samp><dt><samp><span class="option">--show-all</span></samp><dd>Incorporate all unmerged changes from <var>older</var> to <var>yours</var> into
<var>mine</var>, surrounding conflicts with bracket lines.
See <a href="#Marking-Conflicts">Marking Conflicts</a>.
<br><dt><samp><span class="option">--diff-program=</span><var>program</var></samp><dd>Use the compatible comparison program <var>program</var> to compare files
instead of <samp><span class="command">diff</span></samp>.
<br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Generate an <samp><span class="command">ed</span></samp> script that incorporates all the changes from
<var>older</var> to <var>yours</var> into <var>mine</var>. See <a href="#Which-Changes">Which Changes</a>.
<br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--show-overlap</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except bracket lines from overlapping changes' first
and third files.
See <a href="#Marking-Conflicts">Marking Conflicts</a>.
With <samp><span class="option">-E</span></samp>, an overlapping change looks like this:
<pre class="example"> <<<<<<< <var>mine</var>
<span class="roman">lines from </span><var>mine</var>
=======
<span class="roman">lines from </span><var>yours</var>
>>>>>>> <var>yours</var>
</pre>
<br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
<br><dt><samp><span class="option">-i</span></samp><dd>Generate `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>' commands at the end of the <samp><span class="command">ed</span></samp>
script for System V compatibility. This option must be combined with
one of the <samp><span class="option">-AeExX3</span></samp> options, and may not be combined with <samp><span class="option">-m</span></samp>.
See <a href="#Saving-the-Changed-File">Saving the Changed File</a>.
<br><dt><samp><span class="option">-L </span><var>label</var></samp><dt><samp><span class="option">--label=</span><var>label</var></samp><dd>Use the label <var>label</var> for the brackets output by the <samp><span class="option">-A</span></samp>,
<samp><span class="option">-E</span></samp> and <samp><span class="option">-X</span></samp> options. This option may be given up to three
times, one for each input file. The default labels are the names of
the input files. Thus `<samp><span class="samp">diff3 -L X -L Y -L Z -m A B C</span></samp>' acts like
`<samp><span class="samp">diff3 -m A B C</span></samp>', except that the output looks like it came from
files named `<samp><span class="samp">X</span></samp>', `<samp><span class="samp">Y</span></samp>' and `<samp><span class="samp">Z</span></samp>' rather than from files
named `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>' and `<samp><span class="samp">C</span></samp>'. See <a href="#Marking-Conflicts">Marking Conflicts</a>.
<br><dt><samp><span class="option">-m</span></samp><dt><samp><span class="option">--merge</span></samp><dd>Apply the edit script to the first file and send the result to standard
output. Unlike piping the output from <samp><span class="command">diff3</span></samp> to <samp><span class="command">ed</span></samp>, this
works even for binary files and incomplete lines. <samp><span class="option">-A</span></samp> is assumed
if no edit script option is specified. See <a href="#Bypassing-ed">Bypassing ed</a>.
<br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--initial-tab</span></samp><dd>Output a tab rather than two spaces before the text of a line in normal format.
This causes the alignment of tabs in the line to look normal. See <a href="#Tabs">Tabs</a>.
<br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
<br><dt><samp><span class="option">-x</span></samp><dt><samp><span class="option">--overlap-only</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except output only the overlapping changes.
See <a href="#Which-Changes">Which Changes</a>.
<br><dt><samp><span class="option">-X</span></samp><dd>Like <samp><span class="option">-E</span></samp>, except output only the overlapping changes.
In other words, like <samp><span class="option">-x</span></samp>, except bracket changes as in <samp><span class="option">-E</span></samp>.
See <a href="#Marking-Conflicts">Marking Conflicts</a>.
<br><dt><samp><span class="option">-3</span></samp><dt><samp><span class="option">--easy-only</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except output only the nonoverlapping changes.
<p>You can also specify where to read the patch from with the <samp><span class="option">-i
</span><var>patchfile</var></samp> or <samp><span class="option">--input=</span><var>patchfile</var></samp> option.
If you do not specify <var>patchfile</var>, or if <var>patchfile</var> is
<samp><span class="file">-</span></samp>, <samp><span class="command">patch</span></samp> reads the patch (that is, the <samp><span class="command">diff</span></samp> output)
from the standard input.
<p>If you do not specify an input file on the command line, <samp><span class="command">patch</span></samp>
tries to intuit from the <dfn>leading text</dfn> (any text in the patch
that comes before the <samp><span class="command">diff</span></samp> output) which file to edit.
See <a href="#Multiple-Patches">Multiple Patches</a>.
<p>By default, <samp><span class="command">patch</span></samp> replaces the original input file with the
patched version, possibly after renaming the original file into a
backup file (see <a href="#Backup-Names">Backup Names</a>, for a description of how
<samp><span class="command">patch</span></samp> names backup files). You can also specify where to
put the output with the <samp><span class="option">-o </span><var>file</var></samp> or
<samp><span class="option">--output=</span><var>file</var></samp> option; however, do not use this option
if <var>file</var> is one of the input files.
<ul class="menu">
<li><a accesskey="1" href="#patch-Options">patch Options</a>: Summary table of options to <samp><span class="command">patch</span></samp>.
Here is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>
accepts. See <a href="#patch-and-Tradition">patch and Tradition</a>, for which of these options are
safe to use in older versions of <samp><span class="command">patch</span></samp>.
<p>Multiple single-letter options that do not take an argument can be
combined into a single command line argument with only one dash.
<dl>
<dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--backup</span></samp><dd>Back up the original contents of each file, even if backups would
normally not be made. See <a href="#Backups">Backups</a>.
<br><dt><samp><span class="option">-B </span><var>prefix</var></samp><dt><samp><span class="option">--prefix=</span><var>prefix</var></samp><dd>Prepend <var>prefix</var> to backup file names. See <a href="#Backup-Names">Backup Names</a>.
<br><dt><samp><span class="option">--backup-if-mismatch</span></samp><dd>Back up the original contents of each file if the patch does not
exactly match the file. This is the default behavior when not
conforming to <span class="sc">posix</span>. See <a href="#Backups">Backups</a>.
<br><dt><samp><span class="option">--binary</span></samp><dd>Read and write all files in binary mode, except for standard output
and <samp><span class="file">/dev/tty</span></samp>. This option has no effect on
<span class="sc">posix</span>-conforming systems like <span class="sc">gnu</span>/Linux. On systems where
this option makes a difference, the patch should be generated by
`<samp><span class="samp">diff -a --binary</span></samp>'. See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">-c</span></samp><dt><samp><span class="option">--context</span></samp><dd>Interpret the patch file as a context diff. See <a href="#patch-Input">patch Input</a>.
<br><dt><samp><span class="option">-d </span><var>directory</var></samp><dt><samp><span class="option">--directory=</span><var>directory</var></samp><dd>Make directory <var>directory</var> the current directory for interpreting
both file names in the patch file, and file names given as arguments to
other options. See <a href="#patch-Directories">patch Directories</a>.
<br><dt><samp><span class="option">-D </span><var>name</var></samp><dt><samp><span class="option">--ifdef=</span><var>name</var></samp><dd>Make merged if-then-else output using <var>name</var>. See <a href="#If_002dthen_002delse">If-then-else</a>.
<br><dt><samp><span class="option">--dry-run</span></samp><dd>Print the results of applying the patches without actually changing
any files. See <a href="#Dry-Runs">Dry Runs</a>.
<br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Interpret the patch file as an <samp><span class="command">ed</span></samp> script. See <a href="#patch-Input">patch Input</a>.
<br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--remove-empty-files</span></samp><dd>Remove output files that are empty after the patches have been applied.
See <a href="#Creating-and-Removing">Creating and Removing</a>.
<br><dt><samp><span class="option">-f</span></samp><dt><samp><span class="option">--force</span></samp><dd>Assume that the user knows exactly what he or she is doing, and do not
ask any questions. See <a href="#patch-Messages">patch Messages</a>.
<br><dt><samp><span class="option">-F </span><var>lines</var></samp><dt><samp><span class="option">--fuzz=</span><var>lines</var></samp><dd>Set the maximum fuzz factor to <var>lines</var>. See <a href="#Inexact">Inexact</a>.
<br><dt><samp><span class="option">-g </span><var>num</var></samp><dt><samp><span class="option">--get=</span><var>num</var></samp><dd>If <var>num</var> is positive, get input files from a revision control
system as necessary; if zero, do not get the files; if negative, ask
the user whether to get the files. See <a href="#Revision-Control">Revision Control</a>.
<br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
<br><dt><samp><span class="option">-i </span><var>patchfile</var></samp><dt><samp><span class="option">--input=</span><var>patchfile</var></samp><dd>Read the patch from <var>patchfile</var> rather than from standard input.
See <a href="#patch-Options">patch Options</a>.
<br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--ignore-white-space</span></samp><dd>Let any sequence of blanks (spaces or tabs) in the patch file match
any sequence of blanks in the input file. See <a href="#Changed-White-Space">Changed White Space</a>.
<br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--normal</span></samp><dd>Interpret the patch file as a normal diff. See <a href="#patch-Input">patch Input</a>.
<br><dt><samp><span class="option">-N</span></samp><dt><samp><span class="option">--forward</span></samp><dd>Ignore patches that <samp><span class="command">patch</span></samp> thinks are reversed or already applied.
See also <samp><span class="option">-R</span></samp>. See <a href="#Reversed-Patches">Reversed Patches</a>.
<br><dt><samp><span class="option">--no-backup-if-mismatch</span></samp><dd>Do not back up the original contents of files. This is the default
behavior when conforming to <span class="sc">posix</span>. See <a href="#Backups">Backups</a>.
<br><dt><samp><span class="option">-o </span><var>file</var></samp><dt><samp><span class="option">--output=</span><var>file</var></samp><dd>Use <var>file</var> as the output file name. See <a href="#patch-Options">patch Options</a>.
<br><dt><samp><span class="option">-p</span><var>number</var></samp><dt><samp><span class="option">--strip=</span><var>number</var></samp><dd>Set the file name strip count to <var>number</var>. See <a href="#patch-Directories">patch Directories</a>.
<br><dt><samp><span class="option">--posix</span></samp><dd>Conform to <span class="sc">posix</span>, as if the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment
variable had been set. See <a href="#patch-and-POSIX">patch and POSIX</a>.
<br><dt><samp><span class="option">--quoting-style=</span><var>word</var></samp><dd>Use style <var>word</var> to quote names in diagnostics, as if the
<samp><span class="env">QUOTING_STYLE</span></samp> environment variable had been set to <var>word</var>.
See <a href="#patch-Quoting-Style">patch Quoting Style</a>.
<br><dt><samp><span class="option">-r </span><var>reject-file</var></samp><dt><samp><span class="option">--reject-file=</span><var>reject-file</var></samp><dd>Use <var>reject-file</var> as the reject file name. See <a href="#Reject-Names">Reject Names</a>.
<br><dt><samp><span class="option">-R</span></samp><dt><samp><span class="option">--reverse</span></samp><dd>Assume that this patch was created with the old and new files swapped.
See <a href="#Reversed-Patches">Reversed Patches</a>.
<br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd>Work silently unless an error occurs. See <a href="#patch-Messages">patch Messages</a>.
<br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--batch</span></samp><dd>Do not ask any questions. See <a href="#patch-Messages">patch Messages</a>.
<br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--set-time</span></samp><dd>Set the modification and access times of patched files from time
stamps given in context diff headers, assuming that the context diff
headers use local time. See <a href="#Patching-Time-Stamps">Patching Time Stamps</a>.
<br><dt><samp><span class="option">-u</span></samp><dt><samp><span class="option">--unified</span></samp><dd>Interpret the patch file as a unified diff. See <a href="#patch-Input">patch Input</a>.
<br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
<br><dt><samp><span class="option">-V </span><var>backup-style</var></samp><dt><samp><span class="option">--version=control=</span><var>backup-style</var></samp><dd>Select the naming convention for backup file names. See <a href="#Backup-Names">Backup Names</a>.
<br><dt><samp><span class="option">--verbose</span></samp><dd>Print more diagnostics than usual. See <a href="#patch-Messages">patch Messages</a>.
<br><dt><samp><span class="option">-x </span><var>number</var></samp><dt><samp><span class="option">--debug=</span><var>number</var></samp><dd>Set internal debugging flags. Of interest only to <samp><span class="command">patch</span></samp>
patchers.
<br><dt><samp><span class="option">-Y </span><var>prefix</var></samp><dt><samp><span class="option">--basename-prefix=</span><var>prefix</var></samp><dd>Prepend <var>prefix</var> to base names of backup files. See <a href="#Backup-Names">Backup Names</a>.
<br><dt><samp><span class="option">-z </span><var>suffix</var></samp><dt><samp><span class="option">--suffix=</span><var>suffix</var></samp><dd>Use <var>suffix</var> as the backup extension instead of `<samp><span class="samp">.orig</span></samp>' or
`<samp><span class="samp">~</span></samp>'. See <a href="#Backup-Names">Backup Names</a>.
<br><dt><samp><span class="option">-Z</span></samp><dt><samp><span class="option">--set-utc</span></samp><dd>Set the modification and access times of patched files from time
stamps given in context diff headers, assuming that the context diff
headers use <span class="sc">utc</span>. See <a href="#Patching-Time-Stamps">Patching Time Stamps</a>.
<p>This merges <var>from-file</var> with <var>to-file</var>, with output to <var>outfile</var>.
If <var>from-file</var> is a directory and <var>to-file</var> is not, <samp><span class="command">sdiff</span></samp>
compares the file in <var>from-file</var> whose file name is that of <var>to-file</var>,
and vice versa. <var>from-file</var> and <var>to-file</var> may not both be
directories.
<p><samp><span class="command">sdiff</span></samp> options begin with `<samp><span class="samp">-</span></samp>', so normally <var>from-file</var>
and <var>to-file</var> may not begin with `<samp><span class="samp">-</span></samp>'. However, <samp><span class="option">--</span></samp> as an
argument by itself treats the remaining arguments as file names even if
they begin with `<samp><span class="samp">-</span></samp>'. You may not use <samp><span class="file">-</span></samp> as an input file.
<p><samp><span class="command">sdiff</span></samp> without <samp><span class="option">-o</span></samp> (or <samp><span class="option">--output</span></samp>) produces a
side-by-side difference. This usage is obsolete; use the <samp><span class="option">-y</span></samp>
or <samp><span class="option">--side-by-side</span></samp> option of <samp><span class="command">diff</span></samp> instead.
<p>An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.
<ul class="menu">
<li><a accesskey="1" href="#sdiff-Options">sdiff Options</a>: Summary of options to <samp><span class="command">diff</span></samp>.
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">sdiff</span></samp> accepts.
Each option has two equivalent names, one of which is a single
letter preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name
preceded by `<samp><span class="samp">--</span></samp>'. Multiple single letter options (unless they take
an argument) can be combined into a single command line argument. Long
named options can be abbreviated to any unique prefix of their name.
<dl>
<dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
do not appear to be text. See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--ignore-space-change</span></samp><dd>Ignore changes in amount of white space. See <a href="#White-Space">White Space</a>.
<br><dt><samp><span class="option">-B</span></samp><dt><samp><span class="option">--ignore-blank-lines</span></samp><dd>Ignore changes that just insert or delete blank lines. See <a href="#Blank-Lines">Blank Lines</a>.
<br><dt><samp><span class="option">-d</span></samp><dt><samp><span class="option">--minimal</span></samp><dd>Change the algorithm to perhaps find a smaller set of changes. This
makes <samp><span class="command">sdiff</span></samp> slower (sometimes much slower). See <a href="#diff-Performance">diff Performance</a>.
<br><dt><samp><span class="option">--diff-program=</span><var>program</var></samp><dd>Use the compatible comparison program <var>program</var> to compare files
instead of <samp><span class="command">diff</span></samp>.
<br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--ignore-tab-expansion</span></samp><dd>Ignore changes due to tab expansion.
See <a href="#White-Space">White Space</a>.
<br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.
<br><dt><samp><span class="option">-i</span></samp><dt><samp><span class="option">--ignore-case</span></samp><dd>Ignore changes in case; consider upper- and lower-case to be the same.
See <a href="#Case-Folding">Case Folding</a>.
<br><dt><samp><span class="option">-I </span><var>regexp</var></samp><dt><samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp><dd>Ignore changes that just insert or delete lines that match <var>regexp</var>.
See <a href="#Specified-Folding">Specified Folding</a>.
<br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--left-column</span></samp><dd>Print only the left column of two common lines.
See <a href="#Side-by-Side-Format">Side by Side Format</a>.
<br><dt><samp><span class="option">-o </span><var>file</var></samp><dt><samp><span class="option">--output=</span><var>file</var></samp><dd>Put merged output into <var>file</var>. This option is required for merging.
<br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--suppress-common-lines</span></samp><dd>Do not print common lines. See <a href="#Side-by-Side-Format">Side by Side Format</a>.
<br><dt><samp><span class="option">--speed-large-files</span></samp><dd>Use heuristics to speed handling of large files that have numerous
scattered small changes. See <a href="#diff-Performance">diff Performance</a>.
<br><dt><samp><span class="option">--strip-trailing-cr</span></samp><dd>Strip any trailing carriage return at the end of an input line.
See <a href="#Binary">Binary</a>.
<br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--expand-tabs</span></samp><dd>Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files. See <a href="#Tabs">Tabs</a>.
<br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.
<br><dt><samp><span class="option">-w </span><var>columns</var></samp><dt><samp><span class="option">--width=</span><var>columns</var></samp><dd>Output at most <var>columns</var> (default 130) print columns per line.
See <a href="#Side-by-Side-Format">Side by Side Format</a>. Note that for historical reasons, this
option is <samp><span class="option">-W</span></samp> in <samp><span class="command">diff</span></samp>, <samp><span class="option">-w</span></samp> in <samp><span class="command">sdiff</span></samp>.
<br><dt><samp><span class="option">-W</span></samp><dt><samp><span class="option">--ignore-all-space</span></samp><dd>Ignore white space when comparing lines. See <a href="#White-Space">White Space</a>.
Note that for historical reasons, this option is <samp><span class="option">-w</span></samp> in <samp><span class="command">diff</span></samp>,
<samp><span class="option">-W</span></samp> in <samp><span class="command">sdiff</span></samp>.
<a name="index-POSIXLY_005fCORRECT-160"></a>In a few cases, the <span class="sc">gnu</span> utilities' default behavior is
incompatible with the <span class="sc">posix</span> standard. To suppress these
incompatibilities, define the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment
variable. Unless you are checking for <span class="sc">posix</span> conformance, you
probably do not need to define <samp><span class="env">POSIXLY_CORRECT</span></samp>.
<p>Normally options and operands can appear in any order, and programs act
as if all the options appear before any operands. For example,
`<samp><span class="samp">diff lao tzu -C 2</span></samp>' acts like `<samp><span class="samp">diff -C 2 lao tzu</span></samp>', since
`<samp><span class="samp">2</span></samp>' is an option-argument of <samp><span class="option">-C</span></samp>. However, if the
<samp><span class="env">POSIXLY_CORRECT</span></samp> environment variable is set, options must appear
before operands, unless otherwise specified for a particular command.
<p>Newer versions of <span class="sc">posix</span> are occasionally incompatible with older
versions. For example, older versions of <span class="sc">posix</span> allowed the
command `<samp><span class="samp">diff -c -10</span></samp>' to have the same meaning as `<samp><span class="samp">diff -C
10</span></samp>', but <span class="sc">posix</span> 1003.1-2001 `<samp><span class="samp">diff</span></samp>' no longer allows
digit-string options like <samp><span class="option">-10</span></samp>.
<p><a name="index-g_t_005fPOSIX2_005fVERSION-161"></a>The <span class="sc">gnu</span> utilities normally conform to the version of <span class="sc">posix</span>
that is standard for your system. To cause them to conform to a
different version of <span class="sc">posix</span>, define the <samp><span class="env">_POSIX2_VERSION</span></samp>
environment variable to a value of the form <var>yyyymm</var> specifying
the year and month the standard was adopted. Two values are currently
supported for <samp><span class="env">_POSIX2_VERSION</span></samp>: `<samp><span class="samp">199209</span></samp>' stands for
<span class="sc">posix</span> 1003.2-1992, and `<samp><span class="samp">200112</span></samp>' stands for <span class="sc">posix</span>
1003.1-2001. For example, if you are running older software that
assumes an older version of <span class="sc">posix</span> and uses `<samp><span class="samp">diff -c -10</span></samp>',
you can work around the compatibility problems by setting
`<samp><span class="samp">_POSIX2_VERSION=199209</span></samp>' in your environment.
<div class="node">
<p><hr>
<a name="Projects"></a>
Next: <a rel="next" accesskey="n" href="#Copying-This-Manual">Copying This Manual</a>,
<samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp> and <samp><span class="command">sdiff</span></samp> treat each line of
input as a string of unibyte characters. This can mishandle multibyte
characters in some cases. For example, when asked to ignore spaces,
<samp><span class="command">diff</span></samp> does not properly ignore a multibyte space character.
<p>Also, <samp><span class="command">diff</span></samp> currently assumes that each byte is one column
wide, and this assumption is incorrect in some locales, e.g., locales
that use UTF-8 encoding. This causes problems with the <samp><span class="option">-y</span></samp> or
<samp><span class="option">--side-by-side</span></samp> option of <samp><span class="command">diff</span></samp>.
<p>These problems need to be fixed without unduly affecting the
performance of the utilities in unibyte environments.
<p>The IBM GNU/Linux Technology Center Internationalization Team has
proposed some patches to support internationalized <samp><span class="command">diff</span></samp>
If you think you have found a bug in <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>,
<samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp>, or <samp><span class="command">sdiff</span></samp>, please report it
<li><a href="#index-columnar-output-36">columnar output</a>: <a href="#Side-by-Side">Side by Side</a></li>
<li><a href="#index-common-mistakes-with-patches-122">common mistakes with patches</a>: <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a></li>
<li><a href="#index-comparing-three-files-58">comparing three files</a>: <a href="#Comparing-Three-Files">Comparing Three Files</a></li>
<li><a href="#index-file-name-alternates-33">file name alternates</a>: <a href="#Alternate-Names">Alternate Names</a></li>
<li><a href="#index-file-names-with-unusual-characters-167">file names with unusual characters</a>: <a href="#Unusual-File-Names">Unusual File Names</a></li>
<li><a href="#index-format-of-_0040command_007bdiff_007d-output-14">format of <samp><span class="command">diff</span></samp> output</a>: <a href="#Output-Formats">Output Formats</a></li>
<li><a href="#index-format-of-_0040command_007bdiff3_007d-output-59">format of <samp><span class="command">diff3</span></samp> output</a>: <a href="#Comparing-Three-Files">Comparing Three Files</a></li>
<li><a href="#index-formats-for-if_002dthen_002delse-line-groups-47">formats for if-then-else line groups</a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
<li><a href="#index-overview-of-_0040command_007bdiff_007d-and-_0040command_007bpatch_007d-1">overview of <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></a>: <a href="#Overview">Overview</a></li>
<a name="texinfo-footnotes-in-document"></a><h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> A coding error in <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> version
2.5.4 causes it to always use `<samp><span class="samp">~</span></samp>', but this should be fixed in